using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using Dapper;
using EP.Base.BaseService.Manager.Config;
using EP.Base.BaseService.Manager.Dal.Helper;
using EP.Base.BaseService.Manager.Interface.Data;
using EP.Base.BaseService.Manager.Model.Entity;

namespace EP.Base.BaseService.Manager.Dal
{    
	/// <summary>
    /// LogstashConfigLog 
    /// </summary>
    public class LogstashConfigLogs:ILogstashConfigLogs
    {

		/// <summary>
		/// 添加LogstashConfigLog
		/// </summary>
		/// <param name="logstashconfiglog"></param>
		/// <returns></returns>
		public int Add(LogstashConfigLog logstashconfiglog)
		{
			string sql = @"INSERT INTO [LogstashConfigLog]
			([IndexConfig],[InputType],[OutputType],[Schedule],[Server],[UseState],[ConfFileName],[CreateTime])
			VALUES
			(@IndexConfig,@InputType,@OutputType,@Schedule,@Server,@UseState,@ConfFileName,@CreateTime) 
			SELECT SCOPE_IDENTITY()
			";
			var par = new DynamicParameters();
			par.Add("@IndexConfig",logstashconfiglog.IndexConfig , DbType.Int32);
			par.Add("@InputType",logstashconfiglog.InputType , DbType.AnsiString);
			par.Add("@OutputType",logstashconfiglog.OutputType , DbType.AnsiString);
			par.Add("@Schedule",logstashconfiglog.Schedule , DbType.AnsiString);
            par.Add("@Server", logstashconfiglog.Server, DbType.AnsiString);
            par.Add("@UseState", logstashconfiglog.UseState, DbType.AnsiString);
            par.Add("@ConfFileName", logstashconfiglog.ConfFileName, DbType.AnsiString);
			par.Add("@CreateTime",logstashconfiglog.CreateTime , DbType.DateTime);
			return DapWrapper.InnerQueryScalarSql<int>(DbConfig.EpBaseServiceManagerConnectionString, sql, par);
		}
		/// <summary>
		/// 修改LogstashConfigLog
		/// </summary>
		/// <param name="logstashconfiglog"></param>
		/// <returns></returns> 
		public int Update(LogstashConfigLog logstashconfiglog)
		{
			string sql = @"UPDATE  [LogstashConfigLog] SET 
						IndexConfig=@IndexConfig,
						InputType=@InputType,
						OutputType=@OutputType,
						Schedule=@Schedule,
						Server=@Server,
						UseState=@UseState,
                        ConfFileName=@ConfFileName,
						CreateTime=@CreateTime
 WHERE Id=@Id";
			var par = new DynamicParameters();
			par.Add("@Id", logstashconfiglog.Id, DbType.Int32);
			par.Add("@IndexConfig",logstashconfiglog.IndexConfig , DbType.Int32);
			par.Add("@InputType",logstashconfiglog.InputType , DbType.AnsiString);
			par.Add("@OutputType",logstashconfiglog.OutputType , DbType.AnsiString);
			par.Add("@Schedule",logstashconfiglog.Schedule , DbType.AnsiString);
			par.Add("@Server",logstashconfiglog.Server , DbType.AnsiString);
            par.Add("@UseState", logstashconfiglog.UseState, DbType.AnsiString);
            par.Add("@ConfFileName", logstashconfiglog.ConfFileName, DbType.AnsiString);
			par.Add("@CreateTime",logstashconfiglog.CreateTime , DbType.DateTime);
			return DapWrapper.InnerExecuteSql(DbConfig.EpBaseServiceManagerConnectionString, sql, par);
		}
		/// <summary>
		/// 根据id获取LogstashConfigLog
		/// </summary>
		/// <param name="id"></param>
		/// <returns></returns>
		public LogstashConfigLog Get(int id)
		{
            string sql = "select [Id],[IndexConfig],[InputType],[OutputType],[Schedule],[Server],[UseState],[ConfFileName],[CreateTime] FROM [LogstashConfigLog] WHERE Id=@Id";
			var par = new DynamicParameters();
			par.Add("@Id", id, DbType.Int32);
			return DapWrapper.InnerQuerySql<LogstashConfigLog>(DbConfig.EpBaseServiceManagerConnectionString, sql, par).FirstOrDefault();
		}
		/// <summary>
		/// 根据id删除LogstashConfigLog
		/// </summary>
		/// <param name="id"></param>
		/// <returns></returns>
		public Int32 Delete(int id)
		{
			string sql="DELETE [LogstashConfigLog] WHERE Id=@Id";
			var par = new DynamicParameters();
			par.Add("@Id", id, DbType.Int32);
			return DapWrapper.InnerExecuteSql(DbConfig.EpBaseServiceManagerConnectionString, sql, par);
		}
		/// <summary>
		/// 根据ids删除LogstashConfigLog多条记录
		/// </summary>
		/// <param name="ids"></param>
		/// <returns></returns>
		public Int32 Deletes(int[] ids)
		{
			if (ids.Length == 0)
                return 0;
			string sql="DELETE [LogstashConfigLog] WHERE Id IN ("+string.Join(",",ids)+")";
			return DapWrapper.InnerExecuteText(DbConfig.EpBaseServiceManagerConnectionString, sql);
		}
		/// <summary>
       /// 获取LogstashConfigLog分页列表
       /// </summary>
       /// <param name="pageIndex">页码</param>
       /// <param name="pageSize">每页显示条数</param>
       /// <param name="beginTime">开始时间</param>
       /// <param name="endTime">结束时间</param>
       /// <param name="recordCount">总记录数</param>
       /// <returns>LogstashConfigLog列表</returns>
       public List<LogstashConfigLog> GetPageList(int pageIndex, int pageSize, DateTime? beginTime, DateTime? endTime, out int recordCount)
       {
           recordCount = 0;
           var par = new DynamicParameters();
           par.Add("@PageIndex", pageIndex, DbType.Int32);
           par.Add("@PageSize", pageSize, DbType.Int32);
           par.Add("@BeginTime", beginTime, DbType.DateTime);
           par.Add("@EndTime", !endTime.HasValue ? endTime : endTime.Value.AddDays(1).AddMilliseconds(-1), DbType.DateTime);
           par.Add("@TotalCount", recordCount, DbType.Int32, ParameterDirection.Output);
           var result = DapWrapper.InnerQueryProc<LogstashConfigLog>(DbConfig.EpBaseServiceManagerConnectionString, "proc_GetLogstashConfigLogPageList", par);
           recordCount = par.Get<int>("@TotalCount");
           return result;
       }
	   /// <summary>
		/// 获取所有LogstashConfigLog
		/// </summary>
		/// <returns></returns>
		public List<LogstashConfigLog> GetAll()
		{
            string sql = "select [Id],[IndexConfig],[InputType],[OutputType],[Schedule],[Server],[UseState],[ConfFileName],[CreateTime] FROM [LogstashConfigLog] WHERE Id=@Id";
			
			return DapWrapper.InnerQuerySql<LogstashConfigLog>(DbConfig.EpBaseServiceManagerConnectionString, sql);
		}
    }
}
